import md5 from 'js-md5'
/**
 * 字典排序和拼接字符串
 * @param {Object} obj
 */
export const getMd5 = (obj1, obj2, salt) => {
	let mergeObj = {
		...obj1,
		...obj2
	}
	let keyarr = Object.keys(mergeObj).sort();
	let newObj = {}
	for (let i = 0; i < keyarr.length; i++) {
		newObj[keyarr[i]] = mergeObj[keyarr[i]]
	}
	let strArr = []
	for (let [key, value] of Object.entries(newObj)) {
		strArr.push(`${key}=${value}`)
	}
	return {
		obj: newObj,
		sign: md5(strArr.join("&")+salt).toUpperCase()
	}
}


/**
 * 转换手机号, 用****代替
 * @param str
 * @returns {*|string}
 */
//mobile.replace(/(\d{3})\d{4}(\d{4})/, "$1****$2")
export const convertMobileStr=(str)=>{
  if(str.length==11){
    return str.substring(0,3)+"****"+str.substring(7,11)
  }
  return str
}

/**
 * 转换身份证号, 用****代替
 * @param str
 * @returns {string}
 */
//idNumber.replace(/(\d{6})\w{10}(\w{2})/, "$1******$2")
export const conertIdCardStr=(str)=>{
  if(str.length==18){
    return str.substring(0,6)+"********"+str.substring(14,18)
  }
  return str
}